package com.yhsimon.udp;


import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

//实际上UDP中无服务端客户端概念，仅模拟，且不需要连接服务器
public class UdpClientDemo1 {
    public static void main(String[] args) throws Exception {
        //1.建立一个socket
        DatagramSocket socket = new DatagramSocket(9090);

        //2.建一个包
        String msg="你好呀！服务器";
        InetAddress localhost = InetAddress.getByName("localhost");

        DatagramPacket packet = new DatagramPacket(msg.getBytes(),0 ,msg.getBytes().length ,localhost ,8888);
        //3.发送包
        socket.send(packet);
        //4.关闭资源
        socket.close();
    }

}
